home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / indeo / nwxmas / xd_init.c < prev    next >
Text File  |  1993-12-13  |  6KB  |  254 lines

  1. /*
  2. **    ╔══════════════════════════════════════════════════════════════╗
  3. **    ║                                                              ║
  4. **    ║     Copyright (c) 1993 Digital Video Arts, Ltd.              ║
  5. **    ║                    All Rights Reserved                       ║
  6. **    ║                                                              ║
  7. **    ╚══════════════════════════════════════════════════════════════╝
  8. **
  9. **    Christmas card demo
  10. **
  11. **    file: xd_init.c - handle all initialization
  12. */
  13. #include <stdio.h>
  14. #include <fcntl.h>
  15. #include "nw.h"
  16. #include "nwau.h"
  17. #include "nwerrno.h"
  18. #include "xmasdemo.h"
  19.  
  20. static U16 mempool[] = {0, 0xff00, 0xffff, 0xffff};
  21.  
  22. void InitNewworld()
  23. {
  24.     ColorVal c;
  25.     Rect r;
  26.     Point p;
  27.     Font *f;
  28.     DisplayStat far *ds;
  29.  
  30.     NwBegin();
  31.     ds = VidStat();
  32.     if(ds->ver_major < 3) 
  33.         NwErr("This demo requires NewWorld version 3.0 or later");
  34.     VidMemInit(mempool);
  35.  
  36.     //
  37.     // preload microcode
  38.     //
  39.     GrCopyTrans(NULL, &p, NULL, &r, c);
  40.     GrCopyMap(NULL, &r, NULL, &p, NULL, &r, 1);
  41.     GrFontWidth(NULL,XMASGREETING,1);
  42.     GrFontOpen(NULL);
  43.     GrFontHeight(NULL);
  44.     GrFontClose(NULL);
  45.     GrText(NULL, f, &p, XMASGREETING, 0, 1, c, c, c, c);
  46.     GrSpawnBitmap(NULL, &r);
  47.     GrScaleFast(NULL, &r, NULL, &r);
  48.     GrRect(NULL, &r, c, 1, 1, RopDst);
  49.     GrReplace(NULL, &r.origin, NULL, &r, 0xf0, 0xff,0xfe, NULL, 1, 1);
  50.     GrColor(NULL, P_C, c);
  51.     GrEllipse(NULL, &r, c, 1);
  52.  
  53. }
  54.  
  55. void InitDisplays()
  56. {
  57.     VidRegGen(d[0] = VidDispAlloc(VideoC, 256, 240, BM1Y, BM1VU));
  58.     VidRegGen(d[1] = VidDispAlloc(VideoC, 256, 240, BM2Y, BM2VU));
  59.     VidRegGen(d[2] = VidDispAlloc(VideoC, 256, 240, BM3Y, BM3VU));
  60.     VidRegGen(d[3] = VidDispAlloc(VideoC, 256, 240, BM4Y, BM4VU));
  61.     VidRegGen(d[4] = VidDispAlloc(VideoC, 256, 240, BM5Y, BM5VU));
  62.     VidDisplays(&d[0], 5);
  63.  
  64.     VidRegGen(onscreen = VidDispAlloc(VideoC,512,476,ONSCRY,ONSCRVU));
  65. //
  66. //    Note: these offscreen bitmaps don't need any V and U bitmaps since
  67. //    all offscreen operations will only be performed on the Y or CLUT
  68. //    bitmap.
  69. //
  70.     VidRegGen(map = VidDispAlloc(VideoC, 256, 240, MAPY, 0l));
  71.     VidRegGen(mapg = VidDispAlloc(Graphic16, 128, 240, MAPY, 0l));
  72.     VidRegGen(balls = VidDispAlloc(VideoC, 256, 240, BALLSY, 0L));
  73.     VidRegGen(warp = VidDispAlloc(VideoC, 256, 240, WARPY, 0L));
  74.     VidRegGen(text = VidDispAlloc(VideoC, 256, 240, TEXTY, TEXTVU));
  75. }
  76.  
  77. void InitAvss()
  78. {
  79.     AvS *s;
  80.     vobj vsh;
  81.     int foundvideo = 0;
  82.  
  83.     vsh.size = 0x10000L;
  84.     vsh.bound = 0;
  85.     vsh.addr = GrWork;
  86.     a = AvOpen(VIDEOFILE, O_RDONLY, &vsh);
  87.     if(!a) NwErr("Can't open "VIDEOFILE);
  88.  
  89. //
  90. //    Disable all but the first video stream.
  91. //
  92.     for(s= a->s; s ; s = s->next) {
  93.         switch(s->hdr.subtype) {
  94.         case AVS_Pad:
  95.         case AVS_UnderLay:
  96.         case AVS_Audio:
  97.             s->enable = 0;
  98.             break;
  99.  
  100.         default:
  101.             if(foundvideo) {
  102.                 s->enable = 0;
  103.                 break;
  104.             }
  105. //
  106. //    Now, force the input area to be hard coded.
  107. //
  108.             s->cbe[AvSCb_Data].cb->data.addr = YVU_BUFFER;
  109.             s->cbe[AvSCb_Data].cb->data.size = YVU_SIZE;
  110.             foundvideo = 1;
  111.             break;
  112.         }
  113.     }
  114.     
  115. //
  116. //    Start a read
  117. //
  118.     AvRead(a, a->framecnt);
  119. //
  120. //    Preload input buffers 
  121. //
  122.     AvPreload(a, a->framecnt);
  123. //
  124. //    Disable the full screen video since we are going to copy to
  125. //    the screen.
  126.  
  127.     VidSpeed(VID_IGNORE_MOTIONVIDEO);
  128.  
  129. }
  130.  
  131. static void load(Bitmap *b, char *file)
  132. {
  133.     ImH *img;
  134.     Point p;
  135.  
  136.     if(img = GrImOpen(file, O_RDONLY)) {
  137.         POINT(p,0,0);
  138.         GrImLoad(b, &p, img, 1);
  139.         McWait();    /* in case decompressing not done */
  140.         GrImClose(img);
  141.     }
  142.  
  143.     else
  144.         NwErr("can't open image file\n");
  145. }
  146.  
  147. void InitImages()
  148. {
  149.     int i;
  150.     int height, length;
  151.     Rect r;
  152.     Point p;
  153.     Font *f;
  154.     ColorVal black, white, c, red, ltred, dkred;
  155.  
  156.     RGB(white, 255,255,255);
  157.     RGB(red, 255, 0, 0);
  158.     RGB(ltred,255,128,128);
  159.     RGB(dkred,128,0,0);
  160.     RGB(black, 0, 0, 0);
  161.  
  162. //
  163. //    Clear out old VU bitmaps to avoid smearing
  164. //
  165.     RECT(r, 0, 0, 512, 484);
  166.     RGB(c, 0, 0, 0);
  167.     onscreen->dbm.GrPlanes = P_V|P_V;
  168.     GrRect(&onscreen->dbm, &r, c, 1, 1, RopDst);
  169. //
  170. //    Load the image files
  171. //
  172.     onscreen->dbm.GrPlanes = P_YVU; 
  173.     load(&onscreen->dbm,STILLFILE);
  174.     load(&mapg->dbm,MAPFILE);
  175. //
  176. //    Add greeting
  177. //
  178.     f = GrFontOpen(XMASFONT);
  179.     if(!f) NwErr("Can't open "XMASFONT);
  180.     height = GrFontHeight(f);
  181.     length = GrFontWidth(f,XMASGREETING,1);
  182.     POINT(p, 256-length/2, 480 - height*2);
  183.     onscreen->dbm.GrPlanes = P_C;
  184.     GrText(&onscreen->dbm, f, &p, XMASGREETING, 0, 1, white, black, 
  185.         black, black);        // red on top
  186.     p.x--; p.y--;
  187.     GrText(&onscreen->dbm, f, &p, XMASGREETING, 0, 1, black, red, 
  188.         ltred, dkred);        // shadow behind
  189.     GrFontClose(f);
  190. //
  191. //    Prepare off screen logo bitmap and load logo
  192. //    
  193.     text->dbm.GrPlanes = P_C;
  194.     CLT(c, 0xfe);
  195.     RECT(r, 0,0,256,240);
  196.     GrRect(&text->dbm, &r, c, 1, 1, RopDst);
  197.     load(&text->dbm,LOGOFILE);
  198.     RECT(r, 0, 0, 128, 240);
  199. //
  200. //    turn off the lower order bit of each pixel in the y plane so
  201. //    that it will be interpreted as a CLUT pixel
  202. //
  203.     text->dbm.GrPlanes = P_C;
  204. //
  205. //    Replace all pixel in the range of 0xf0 - 0xff with the transparency
  206. //    color( 0xfe) and all other pixels to white
  207. //
  208.     GrReplace(&text->dbm, &r.origin, &text->dbm, &r, 0xf0, 0xff,
  209.         0xfe, GrColor(&text->dbm, P_C, white), 1, 1);
  210. //
  211. //    Spawn copies of the balls on the screen and color them in
  212. //    on the chroma planes only
  213. //
  214.     onscreen->dbm.GrPlanes = P_V | P_U;
  215.     for(i=0; i< MAXBALLS; i++) {
  216.         RECT(r, Balls[i].p.x, Balls[i].p.y,
  217.             warps[Balls[i].warpno].corner.x,
  218.             warps[Balls[i].warpno].corner.y);
  219.         Balls[i].spawn = GrSpawnBitmap(&onscreen->dbm, &r);
  220.         RGB(c, Balls[i].red, Balls[i].green, Balls[i].blue);
  221.         r.corner.x = (r.corner.x*4)/5;
  222.         r.origin.x += 4;
  223.         r.origin.y += 4;
  224.         r.corner.x -=4;
  225.         r.corner.y -= 4;
  226.         GrEllipse(&onscreen->dbm, &r, c, 1);
  227.     }
  228. //
  229. //    Clear the balls bitmap to the transparency color
  230. //
  231.     YVU(c, 0, 0, 0);
  232.     RECT(r, 0, 0, 256, 240);
  233.     GrRect(&balls->dbm, &r, c, 1, 1, RopDst);
  234. }
  235.  
  236. void InitAudio()
  237. {
  238.     int fd;
  239.  
  240.     fd = VidOpen(AUDIOFILE, O_RDONLY|O_BINARY);
  241.     if(fd <= 0) NwErr("Can't open "AUDIOFILE);
  242.     audiolength = VidFileLength(fd);
  243.     VidRead(fd,AUDIOBUFFER,audiolength);
  244.     channel = AudChOpen("adpcm4e", 2,     // play
  245.         11760,                // filter
  246.         4,                // subframes
  247.         (unsigned int)(132300L/4L),    // sample rate
  248.         30,                 // frames/second
  249.         100,                // left volume
  250.         100,                // right volume
  251.         0);
  252.  
  253. }
  254.